<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of portfolioControllerClass
 *
 * @author nstevens
 */
class portfolioControllerClass {

    public function __construct($model) {
        $this->model = $model;
    }

    public function loginRequest() {
        $this->model->string = $this->model->getPIApproverMainPage();
    }

    public function viewFundingAllocation() {
        $this->model->string = $this->model->getDisplayFundingAllocationsPage();
    }

    function viewPortfolio() {
        $this->model->string = $this->model->getViewPortfolioPage();
    }

    public function fundAllocationSubmit() {
        if (isset($_POST['submit'])) {
            //echo $_POST['submit'];
            if (strcmp("Save Allocation", $_POST['submit']) === 0) {
                $this->processSaveAllocation();
            } else if (strcmp("Save Changes", $_POST['submit']) === 0) {
                $this->processEditAllocation();
            } else if (strcmp("Approve/Disapprove FY Proposals", $_POST['submit']) === 0) {
                $this->getProcessApprovalPage();
            } else if (strcmp("Select Project Fiscal Year", $_POST['submit']) === 0) {
                $this->getProcessApprovalPage();
            }
        } else {
            if (($index = getIndexClickedGenericList("submit", 10)) != -1) {
                if (strcmp("Edit", $_POST["submit$index"]) === 0) {
                    $fy = $_POST["fy$index"];
                    $this->model->string = $this->model->getEditFundingAllocationsPage($fy);
                }                    
            }
        }
    }

    //public function 
    public function getProcessApprovalPage() {
        $this->model->string = $this->model->getApprovalProcessPage();
    }

    //process an approval/disapproval decision
    public function processDecisionSubmit() {
        $url = $this->model->processApprovalDecisionRequest();
        if ($url) {
            header($url);
        } else {
            echo "error";
        }
    }

    public function processSaveAllocation() {
        $url = $this->model->processSaveAllocationRequest();
        if ($url) {
            header($url);
        } else {
            echo "error";
        }
    }

    public function processEditAllocation($index) {
        $url = $this->model->processEditAllocationRequest($index);
        if ($url) {
            header($url);
        } else {
            echo "error";
        }
    }

}

?>
